package org.zeuzgroup.tradeskill.centuryvoyage;

import java.awt.Point;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import org.slf4j.Logger;
import org.zeuzgroup.console.Console;

public class LumberJack {
	static final Logger log = org.slf4j.LoggerFactory.getLogger(LumberJack.class);


	private Robot robot;

	public LumberJack() {
		try {
			robot = new java.awt.Robot();
		} catch (Exception e) {
			// TODO: handle exception
		}

	}

	private void harvest() {
		int count = 100;
		// susspecting mouse to have moved if there was a bite!!!
		Point currentPos = java.awt.MouseInfo.getPointerInfo().getLocation();

		for (int i = 0; i < count; i++) {

			currentPos = java.awt.MouseInfo.getPointerInfo().getLocation();

			keyHitandRelease(robot, KeyEvent.VK_ENTER);
			keyHitandRelease(robot, KeyEvent.VK_ENTER);
			robot.mouseMove(30, 710);
			robot.mousePress(InputEvent.BUTTON1_MASK);
			robot.delay(500);
			robot.mouseRelease(InputEvent.BUTTON1_MASK);
			robot.delay(500);
			robot.mousePress(InputEvent.BUTTON3_MASK);
			robot.delay(500);
			robot.mouseRelease(InputEvent.BUTTON3_MASK);
		}
		logOff(robot);

	}

	private void keyHitandRelease(Robot robot, int event) {
		robot.keyPress(event);
		robot.delay(500);

		robot.keyRelease(event);
	}

	private void logOff(Robot robot) {
		robot.mouseMove(60, 710);
		robot.mousePress(InputEvent.BUTTON1_MASK);
		robot.delay(500);
		robot.mouseRelease(InputEvent.BUTTON1_MASK);
		robot.delay(500);
		robot.mousePress(InputEvent.BUTTON3_MASK);
		robot.delay(500);
		robot.mouseRelease(InputEvent.BUTTON3_MASK);
		log.info("Loggin off");

	}
}
